<?php
/**
 * 礼物(gift)表管理
 * Created by PhpStorm.
 * User: wei
 * Date: 2017/6/15
 * Time: 11:00
 */
class PinkGift extends AdminBase{

    protected $do;

    function __construct(){
        parent::__construct();
        $this->do = 'giftManage';
        $this->{$this->op}();
    }

    function indexAction(){
        include_once template("admin_v2/giftList");
        exit();
    }

    function listAction(){
        $this->fetchData(array_merge([
            'do'     => $this->do,
            'format' => 'json',
            'operate' => 'list',
        ], $this->req));
    }

    function msgdetailAction(){
        $this->fetchData([
            'do'     => $this->do,
            'format' => 'json',
            'operate' => 'detail',
            'id' => $this->req['id']
        ]);
    }

//  编辑
    function editdetailAction(){
        //更新时间为编辑保存时间
        $this->req['update_at'] = strtotime(date('Y-m-d h:i:s'));
        $this->req['icon'] = urlencode($this->req['icon']);
        $this->req['preview'] = urlencode($this->req['preview']);
        $this->req['downurl'] = urlencode($this->req['downurl']);
        $this->fetchData(array_merge([
            'do'     => $this->do,
            'format' => 'json',
            'operate' => 'edit',
        ], $this->req));
    }

    //添加
    function addAction(){
        $this->req['icon'] = urlencode($this->req['icon']);
        $this->req['preview'] = urlencode($this->req['preview']);
        $this->req['downurl'] = urlencode($this->req['downurl']);
        //创建时间为新增时间
        $this->req['create_at'] = strtotime(date('Y-m-d h:i:s'));
        $this->fetchData(array_merge([
            'do'     => $this->do,
            'format' => 'json',
            'operate' => 'add',
        ], $this->req));
    }

//    删除
    function deleteAction(){
        $this->fetchData([
            'do'     => $this->do,
            'format' => 'json',
            'operate' => 'delete',
            'id' => $this->req['id']
        ]);
    }
}

new PinkGift;